from api.models.config import Config
from api.utils.response import success_response, error_response
from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse

# 获取系统配置信息
@csrf_exempt
def get_config(request):
    """
    获取系统配置信息
    返回所有配置项，包括免费用户限制等
    """
    try:
        # 获取所有配置项
        configs = Config.objects.all()
        
        # 将配置转换为字典格式
        config_dict = {}
        for config in configs:
            config_dict[config.key] = config.value
            
        return success_response(data=config_dict, message='获取配置成功')
    except Exception as e:
        return error_response(message=f'获取配置失败: {str(e)}')
